home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / flying-6.11 / graph.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  5.3 KB  |  214 lines

  1. #ifndef _global_h
  2. #    include "global.h"
  3. #endif
  4.  
  5. #ifndef _object_h
  6. #    include "object.h"
  7. #endif
  8. #ifndef _graph_h
  9. #    include "graph.h"
  10. #endif
  11. #ifndef _pball_h
  12. #    include "pball.h"
  13. #endif
  14.  
  15. double    world_x, world_y;
  16. int        max_x, max_y;
  17. double    w2n;
  18. int        wall_click = 0;
  19.  
  20.  
  21.  
  22. void Inside( Vec2 *v ) {
  23. double x=v->X();
  24. double y=v->Y();
  25.  
  26.     if (x<0)                x=0;
  27.     if (x>max_x)        x=max_x;
  28.     if (y<0)                y=0;
  29.     if (y>max_y)        y=max_y;
  30.     *v = Vec2(x,y);
  31. }
  32.  
  33. static const int MAX_BG        = 3;
  34. static const int MAX_BALL    = 15;
  35. static const int MAX_SHADE = 3;
  36. static const int MAX_STAT    = 128;
  37.  
  38.          int                nbg_cols=0;
  39. static const char     *bg_col[MAX_BG];
  40.          unsigned long    bg_pix[MAX_BG];            // aus Planes zusammengesetzt
  41. static unsigned long bg_mask;                        // alle bg-Planes
  42.  
  43.          int                nball_cols=1;
  44. static const char     *ball_col[MAX_BALL] = { "Background-Dummy" };
  45.          unsigned long    ball_pix[MAX_BALL];        // allokierte Pixel
  46. static unsigned long ball_mask;
  47.  
  48.          int                nball_ids =0;
  49.          ColorId            ball_ids[MAX_BALL];        // fⁿr BΣlle verteilte Farb-Ids
  50.  
  51.        int           nstat_cols =0;
  52. static const char        *stat_col[MAX_STAT];
  53.        unsigned long stat_pix[MAX_STAT];        // Static-Colors (unter Cursor)
  54.  
  55. static int                nshade_cols=0;
  56. static const char     *shade_col[MAX_SHADE];
  57. static int m[MAX_SHADE], d[MAX_SHADE];            // Anteil Original : Schatten
  58. static unsigned long    shade_pix[MAX_SHADE];    // aus Planes zusammengesetzt
  59. static unsigned long shade_mask;                // alle Shade-Planes
  60.  
  61. static const char     *cursor_col=0;
  62. static unsigned long    cursor_mask;                // Cursor-Plane
  63.  
  64. void InitColors() {
  65.     nbg_cols   = 0;
  66.     nball_cols = 1;
  67.     nstat_cols = 0;
  68.     nball_ids  = 0;
  69.     nshade_cols= 0;
  70. }
  71.  
  72. unsigned long GetAllocatedPixel( const char *colorname ) {
  73.     for (int i=0;i<nbg_cols;i++)
  74.         if    (!strcmp(bg_col[i],colorname))        return bg_pix[i]|ball_pix[0];
  75.     for (i=0;i<nball_cols;i++)
  76.         if    (!strcmp(ball_col[i],colorname))        return ball_pix[i];
  77.     return 0;
  78. }
  79.  
  80. unsigned long GetAllocatedPixel( ColorId col, int x, int y ) {
  81.     if (col&MIX_MASK) {
  82.         if ( (x^y)&0x01 ) {
  83.             col = (col>>COLOR_BITS);
  84.         }
  85.     }
  86.     if (col&BG_MASK)            return bg_pix[ (int)(col&COLOR_MASK) ];
  87.     else                            return ball_pix[ (int)(col&COLOR_MASK) ];
  88. }
  89.  
  90. ColorId AddBgColor( const char *colorname ) {
  91.     for (int i=0;i<nbg_cols;i++)
  92.         if    (!strcmp(bg_col[i],colorname)) {
  93.             DBG2( ShowColors, "   BG%d: '%s' (reused)\n", i, colorname );
  94.             return i|BG_MASK;
  95.         }
  96.  
  97.     if (nbg_cols<MAX_BG) {
  98.         DBG2( ShowColors, "   BG%d: '%s'\n", nbg_cols, colorname );
  99.         bg_col[nbg_cols] = colorname;
  100.         return (nbg_cols++)|BG_MASK;
  101.     }
  102.     else {
  103.         DBG2( ShowColors, "   BG%d: '%s' *** TOO MANY COLORS\n",
  104.                                                                     nbg_cols, colorname );
  105.         return -1;
  106.     }
  107. }
  108. ColorId AddBallColor( const char *colorname ) {
  109.     for (int i=0;i<nball_cols;i++)
  110.         if    (!strcmp(ball_col[i],colorname)) {
  111.             DBG2( ShowColors, " Ball%d: '%s' (reused)\n", i, colorname );
  112.             return i;
  113.         }
  114.  
  115.     if (nball_cols<MAX_BALL) {
  116.         DBG2( ShowColors, " Ball%d: '%s'\n", nball_cols, colorname );
  117.         ball_col[nball_cols]        = colorname;
  118.         ball_ids[nball_ids++]    = nball_cols;
  119.         return nball_cols++;
  120.     }
  121.     else {
  122.         DBG2( ShowColors, " Ball%d: '%s' *** TOO MANY COLORS\n",
  123.                                                                     nball_cols, colorname );
  124.         return -1;
  125.     }
  126. }
  127. ColorId AddStatColor( const char *colorname ) {
  128.     for (int i=0;i<nstat_cols;i++)
  129.         if    (!strcmp(stat_col[i],colorname)) {
  130.             DBG2( ShowColors, " Stat%d: '%s' (reused)\n", i, colorname );
  131.             return i|STAT_MASK;
  132.         }
  133.  
  134.     if (nstat_cols<MAX_STAT) {
  135.         DBG2( ShowColors, " Stat%d: '%s'\n", nstat_cols, colorname );
  136.         stat_col[nstat_cols]        = colorname;
  137.         return (nstat_cols++)|STAT_MASK;
  138.     }
  139.     else {
  140.         DBG2( ShowColors, " Stat%d: '%s' *** TOO MANY COLORS\n",
  141.                                                                     nstat_cols, colorname );
  142.         return -1;
  143.     }
  144. }
  145. int AddShadeColor( const char *colorname, int mult, int divi ) {
  146.     for (int i=0;i<nshade_cols;i++)
  147.         if    (!strcmp(shade_col[i],colorname))        return i;
  148.  
  149.     if (nshade_cols<MAX_SHADE) {
  150.         DBG2( ShowColors, "Shade%d: '%s'\n", nshade_cols, colorname );
  151.         shade_col[nshade_cols] = colorname;
  152.         m[nshade_cols] = mult;
  153.         d[nshade_cols] = divi;
  154.         return nshade_cols++;
  155.     }
  156.     else {
  157.         DBG2( ShowColors, "Shade%d: '%s' *** TOO MANY COLORS\n",
  158.                                                                     nball_cols, colorname );
  159.         return -1;
  160.     }
  161. }
  162. void SetCursorColor( const char *colorname ) {
  163.     cursor_col = colorname;
  164. }
  165. ColorId SetMainBgColor( const char *colorname ) {
  166.     ball_col[0] = colorname;
  167.     DBG1( ShowColors, "MainBg: '%s' (Ball0)\n", colorname );
  168.     return 0;
  169. }
  170.  
  171. ColorId CreateColorMix( ColorId c1, ColorId c2, int fact ) {
  172.     ColorId    mix = MIX_MASK | (c2<<COLOR_BITS) | c1
  173.                         | ((fact<<RAND_SHIFT)&RAND_MASK);
  174.  
  175.     if (!(c1&BG_MASK)&&!(c2&BG_MASK)) {
  176.         ball_ids[nball_ids++]=mix;
  177.         DBG4( ShowColors, "     %d: Mix %lx + %lx (%d:1)\n",
  178.                                                 nball_ids, c1, c2, fact );
  179.     }
  180.     else {
  181.         DBG3( ShowColors, "         Mix %lx + %lx (%d:1)\n",
  182.                                                 c1, c2, fact );
  183.     }
  184.     return mix;
  185. }
  186.  
  187.  
  188. void ResetColor( ColorId id, const char *colorname ) {
  189.     if (id&MIX_MASK) {
  190.         printf( "error: mix-colors unchangeable\n" );
  191.     }
  192.     else {
  193.         if (id&BG_MASK) {
  194.             DBG2( ShowColors, "   BG%ld: '%s' (Reset)\n", id-BG_MASK, colorname );
  195.             bg_col[(int)(id&COLOR_MASK)]=colorname;
  196.         }
  197.         else if (id&STAT_MASK) {
  198.             DBG2( ShowColors, " Stat%ld: '%s' (Reset)\n", id, colorname );
  199.             stat_col[(int)(id&COLOR_MASK)] = colorname;
  200.         }
  201.         else {
  202.             DBG2( ShowColors, " Ball%ld: '%s' (Reset)\n", id, colorname );
  203.             ball_col[(int)id] = colorname;
  204.         }
  205.     }
  206. }
  207.  
  208. #ifndef __TURBOC__
  209. #    include "xgraph.C"
  210. #else
  211. #    include "dosgraph.C"
  212. #endif
  213.  
  214.